package cn.chencaiju.blog.service;

import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;

import cn.chencaiju.blog.domain.AjaxResponse;
import cn.chencaiju.blog.domain.Category;
import cn.chencaiju.blog.domain.Post;
import cn.chencaiju.blog.mapper.CategoryMapper;

public class CategoryService {

	private CategoryMapper mapper=null;

	public AjaxResponse<Category> page(int pages,int limit){
		System.out.println("page int");
		List<Category> list = mapper.page(pages,limit);
		int count = mapper.count();
		AjaxResponse<Category> response=new AjaxResponse<>();
		response.setData(list);
		response.setCount(count);
		response.setCode(0);
		response.setMsg("successed");
		return response;
	}
	public int delete(int id) {
		return mapper.delete(id);
	}
	public int update(Category cate) {
		return  mapper.update(cate);
		
	}
	public AjaxResponse<Category> page(String pages, String limit) {
		System.out.println("page string ");
		int size=Integer.valueOf(limit);
		int start=(Integer.valueOf(pages)- 1) * size;
		
		return page(start,size);
	}
	public List<Category> findAll() {
		List<Category> data = mapper.findAll();
		return data;
	}
	public int count() {
		return mapper.count();
	}
	public int addCategory(String name, String priority) {
		if(priority==null||priority=="")return -1;
		Category cate=new Category();
		cate.setName(name);
		cate.setPriority(priority);
		return mapper.addCategory(cate);		
	}
}
